import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { User } from '@/types/user'

/**
 * 用户store：存储登录用户信息
 */
export const useUserStore = defineStore(
  'cp-user',
  () => {
    // 使用类型断言将其初始化为空对象
    const user = ref({} as User)

    const setUser = (userData: User) => {
      user.value = userData
    }
    const delUser = () => {
      user.value = {} as User
    }
    return {
      user,
      setUser,
      delUser
    }
  },
  {
    // 该模块的状态将被存储在sessionStorage中
    persist: true
  }
)
